package com.example.wechat.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.project.annotation.Log;
import com.example.project.core.controller.BaseController;
import com.example.project.core.domain.AjaxResult;
import com.example.project.core.page.TableDataInfo;
import com.example.project.enums.BusinessType;
import com.example.project.utils.poi.ExcelUtil;
import com.example.wechat.model.WechatGroupMember;
import com.example.wechat.service.WechatGroupMemberService;

/**
 * 微信群成员Controller
 * 
 * @author ruoyi
 * @date 2025-11-12
 */
@Controller
@RequestMapping("/wechat/member")
public class WechatGroupMemberController extends BaseController {

	private String prefix = "wechat/member";

	@Autowired
	private WechatGroupMemberService wechatGroupMemberService;

	@RequiresPermissions("wechat:member:view")
	@GetMapping()
	public String member() {
		return prefix + "/member";
	}

	/**
	 * 查询微信群成员列表
	 */
	@RequiresPermissions("wechat:member:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WechatGroupMember wechatGroupMember) {
		startPage();
		List<WechatGroupMember> list = wechatGroupMemberService.selectWechatGroupMemberList(wechatGroupMember);
		return getDataTable(list);
	}

	/**
	 * 导出微信群成员列表
	 */
	@RequiresPermissions("wechat:member:export")
	@Log(title = "微信群成员", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(WechatGroupMember wechatGroupMember) {
		List<WechatGroupMember> list = wechatGroupMemberService.selectWechatGroupMemberList(wechatGroupMember);
		ExcelUtil<WechatGroupMember> util = new ExcelUtil<WechatGroupMember>(WechatGroupMember.class);
		return util.exportExcel(list, "微信群成员数据");
	}

	/**
	 * 新增微信群成员
	 */
	@RequiresPermissions("wechat:member:add")
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存微信群成员
	 */
	@RequiresPermissions("wechat:member:add")
	@Log(title = "微信群成员", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WechatGroupMember wechatGroupMember) {
		return toAjax(wechatGroupMemberService.insertWechatGroupMember(wechatGroupMember));
	}

	/**
	 * 修改微信群成员
	 */
	@RequiresPermissions("wechat:member:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		WechatGroupMember wechatGroupMember = wechatGroupMemberService.selectWechatGroupMemberById(id);
		mmap.put("wechatGroupMember", wechatGroupMember);
		return prefix + "/edit";
	}

	/**
	 * 修改保存微信群成员
	 */
	@RequiresPermissions("wechat:member:edit")
	@Log(title = "微信群成员", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WechatGroupMember wechatGroupMember) {
		return toAjax(wechatGroupMemberService.updateWechatGroupMember(wechatGroupMember));
	}

	/**
	 * 删除微信群成员
	 */
	@RequiresPermissions("wechat:member:remove")
	@Log(title = "微信群成员", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(wechatGroupMemberService.deleteWechatGroupMemberByIds(ids));
	}
}
